/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.makimo.fuzzy.sets;

import pl.makimo.fuzzy.sets.memberships.ContinuousMembershipFunction;
import pl.makimo.fuzzy.sets.memberships.MembershipFunction;
import pl.makimo.fuzzy.sets.memberships.Integrable;

/**
 *
 * @author Mateusz Papiernik
 */
public class ContinuousFuzzySet extends DiscreteFuzzySet<Double> {
    private double min;
    private double max;

	public ContinuousFuzzySet(MembershipFunction membershipFunction, double min, double max) {
		super(membershipFunction);
		this.min = min;
		this.max = max;
		generateRange();
	}
	
	public double getMin() {
		return min;
	}

	public void setMin(double min) {
		this.min = min;
		generateRange();
	}

	public double getMax() {
		return max;
	}

	public void setMax(double max) {
		this.max = max;
		generateRange();
	}

	private void generateRange() {
		elements = new CrispSet<Double>();
		
		for (int i = 0; i < (max-min)/0.1; i++) {
			elements.add(i * 0.1);
		}
	}
	
	public ContinuousFuzzySet(MembershipFunction membershipFunction) {
		super(membershipFunction);
	}
	
	@Override
	public CrispSet<Double> support() {
		if (membershipFunction instanceof Integrable) {
				return new ContinuousCrispSet(((Integrable)membershipFunction).min(min), ((Integrable)membershipFunction).max(max));	
		}
		
		/* Work with discrete elements between min and max */
   		return super.support();
    }    	
	
	@Override
    public double crispCardinality() {
   		return max - min;
    }	
	
	@Override
    public double cardinality() {
		if (membershipFunction instanceof Integrable) {
			return ((Integrable)membershipFunction).integrate(min, max);	
		}
	
		/* Work with discrete elements between min and max */
		return super.cardinality();
    }
}
